package com.example.utils;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by alading-qs on 2016/12/27.
 */
public class SessionUtil {

    private static final String CLIENT_IP = "clientIp";
    private static final String USER_ID = "userId";

    private static ThreadLocal<Map<String, Object>> session = new ThreadLocal<Map<String, Object>>() {
        public Map<String, Object> initialValue() {
            return new HashMap<String, Object>();
        }
    };

    public static Long getUserId() {
        return (Long) session.get().get(USER_ID);
    }

    public static String getClientIp() {
        return (String) session.get().get(CLIENT_IP);
    }

    public static void init(String clientId, Long customerId, Long userId, String clientIp) {
        session.get().clear();
        session.get().put(USER_ID, userId);
        session.get().put(CLIENT_IP, clientIp);
    }
}
